Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support running docs builds against worktrees #2130

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tvernum
Copy link
Contributor

@tvernum tvernum commented Jun 7, 2021

The Elasticsearch convention is to use git worktrees to support
multiple lines of development across different branches.

A typical layout would be:

  • A regular checkout at $GIT_HOME/elasticsearch for the master branch
  • A worktree at $GIT_HOME/elasticsearch-7.x for the 7.x branch
  • A worktree at $GIT_HOME/elasticsearch-6.x for the 6.x branch

This commit changes the docs build to support this structure.

The Elasticsearch convention is to use git worktrees to support
multiple lines of development across different branches.

A typical layout would be:
 - A regular checkout at `$GIT_HOME/elasticsearch` for the `master` branch
 - A worktree at `$GIT_HOME/elasticsearch-7.x` for the `7.x` branch
 - A worktree at `$GIT_HOME/elasticsearch-6.x` for the `6.x` branch

This commit changes the docs build to support this structure.
@tvernum tvernum added enhancement Something we'd like to improve docs-build Relates to the build tooling and scripts labels Jun 7, 2021
@tvernum tvernum requested a review from gtback June 7, 2021 05:33
@tvernum
Copy link
Contributor Author

tvernum commented Jun 7, 2021

It's been more than 10 years since I was a perl engineer, so my perl code probably looks more like Java than idiomatic perl.
My python code probably does too :)

There's no tests, because I really wanted to check whether this was useful or not before I put any more time into it.

I originally intended to just detect the worktree style, and fail the build quickly so that ES engineers don't spend time trying to debug it themselves, but then it looked like it might be possible to fix and I went down that rabbit hole.

I don't know what other development practices other projects use, so it's possible this breaks something for another team. I'm happy to iterate on it if needed - or just hand it over if you'd like to run with it yourself.

@gtback
Copy link
Member

gtback commented Jun 9, 2021

Related: #2039

Copy link
Member

@gtback gtback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking the time to look at this, @tvernum. I think this is valuable and worth including; I just had a couple questions about the implementation. I'm not a Perl expert, nor a frequent user of Git worktrees. I don't think it's likely to break anyone's workflows either.

We do have an integration test suite that could probably be expanded to include this as well.

Is support for worktrees only needed for the --resource argument, or also for --sub_dir?

} else {
$d = $p;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get rid of the unless $toplevel below, and then just return 0?

my $p = $d->parent;
if ($p eq $d) {
# Root of this filesystem
$d = undef;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just break here? Or print an error and return immediately? Is there any other way $d could become undefined in this loop?

@@ -169,7 +169,13 @@ def run_build_docs(args):
extra_name = repo_name.replace('x-pack-', '')
repo_mount = '/doc/%s-extra/%s' % (extra_name, repo_name)
else:
repo_mount = '/doc/' + repo_name
match = re.search(r'(.*)-[0-9]+\.[0-9x]+$', repo_name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a pretty safe way to detect "repo names" that include a -<version branch> suffix, and is unlikely to inadvertently catch a non-worktree repo name; the only repo that contains a digit right now is cloud-on-k8s.

Is this pattern for worktree names (elasticsearch, elasticsearch-7.x, elasticsearch-6.x) pretty universal and documented anywhere? I wouldn't want to have a partial solution that only works for this specific setup if it's not universal; if I understand correctly, any other worktrees that don't match this pattern would still fail, right?

Would it be possible to parse the .git file (which on my machine seems to contain something like gitdir: /absolute/path/to/elasticsearch/.git/worktrees/elasticsearch-7.x and find the repo name by looking at the path component before .git?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this would match the pattern I am using for my work trees. I am not aware of any conventions/documentation for how to create these (I have a tiny bash script for personal use)

~/workspace/elasticsearch $ ls
7.0  7.1  7.10  7.11  7.12  7.13  7.14  7.15  7.16  7.17  7.2  7.3  7.4  7.5  7.6  7.7  7.8  7.9  8.0  8.1  8.2  main

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the format that we recommend in the ES development docs

$ git fetch origin 7.x
$ git checkout -b 7.x origin/7.x && git checkout master
$ git worktree add ../elasticsearch-7.x 7.x

I'll try and pick this PR up again and see if I can make it agnostic to the worktree name.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh.. i had missed those. Not a big fan of that layout and the instructions needed updating anyway ... so I am taking a swing at changing the recommendation : https://github.com/elastic/elasticsearch-team/pull/882

@gtback
Copy link
Member

gtback commented Aug 19, 2021

@tvernum I haven't looked into why the tests are failing. Are you able to do that?

@tvernum
Copy link
Contributor Author

tvernum commented Aug 20, 2021

Yes, now that we've branched for 7.15 I should have some cycles to look at this again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs-build Relates to the build tooling and scripts enhancement Something we'd like to improve
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants